const { format } = require('date-fns')
const { v4: uuid } = require('uuid')
const path = require('path')
const fs = require('fs')
const fsPromiss = require('fs').promises

const logEvents = async (message) => {
    const dataTime = `${format(new Date(), 'yyyyMMdd\tHH:mm:ss')}`;
    const logItem = `${dataTime}\t${uuid()}\t ${message} \n`
    console.log(logItem);

    try {
        if (!fs.existsSync(path.join(__dirname, 'logs'))) {
            await fsPromiss.mkdir(path.join(__dirname, 'logs'));
        }
        await fsPromiss.appendFile(path.join(__dirname, 'logs', 'eventLog.txt'), logItem)
    } catch (err) {
        console.err(err)
    }
}

module.exports = logEvents